<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>场地信息</title>
    <link rel="stylesheet" type="text/css" href="/site_jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/site_jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript" src="/site_jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/site_jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/site_jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/site_js/uploadPreview.js"></script>
    <script type="text/javascript" src="/site_js/common.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#applicationTime").datebox({
                onSelect : function(beginDate){
                    if (beginDate<new Date()){
                        $('#applicationTime').datebox('setValue', getCurentDateStr());
                       /* $('#returnTime').datebox('setValue', getCurentDateStr());*/
                    }else {
                       /* $('#returnTime').datebox('setValue', $('#applicationTime').datebox('getValue'));*/
                    }

                    var selectedRows=$("#dg").datagrid('getSelections');
                    var row=selectedRows[0];

                    $('#whenTime').combobox('clear');
                    /*查询可用时间段*/
                    var url = '/siteReservation/getWhenTime?siteId='+row.siteId+'&applicationTime='+$('#applicationTime').datebox('getValue');
                    $('#whenTime').combobox('reload', url);

                }
            });

           /* $("#returnTime").datebox({
                onSelect : function(beginDate){
                    var applicationTime=$('#applicationTime').datebox('getValue');
                    var returnDate=$('#returnTime').datebox('getValue');
                    if (applicationTime > returnDate){
                        console.log(applicationTime);
                        $('#returnTime').datebox('setValue', applicationTime);
                    }

                }
            });*/

        });
        var url;
        function search(){
            $("#dg").datagrid('load',{
                "name":$("#name").combobox("getValue"),
                "position":$("#position").combobox("getValue"),
                "purpose":$("#purpose").combobox("getValue"),
                "status":$("#status").combobox("getValue")
            });
        };

        function openAddDialog(){
            var selectedRows=$("#dg").datagrid('getSelections');
            if(selectedRows.length!=1){
                $.messager.alert("系统提示","请选择一条数据！");
                return;
            }
            var row=selectedRows[0];
            if(row.status!="可租借"){
                $.messager.alert("系统提示","请选择一条可租借的数据！");
                return;
            }
            $('#fm2').form('load',row);
            $("#dlg2").dialog("open").dialog("setTitle","预约场地");

            url="/siteReservation/addSiteReservation";
            $('#applicationTime').datebox('setValue', getCurentDateStr());
             /*  $('#returnTime').datebox('calendar').calendar({

                    validator : function(date){
                        var now = new Date();
                        var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
                        return date > d1;
                    }
                });*/
        };


        function saveSite(){
            $("#fm2").form("submit",{
                url:url,
                onSubmit: function(){
                    // do some check
                    if($("#whenTime").combobox("getValue")==""){
                        $.messager.alert("系统提示","时间段不能为空");
                        return false;
                    }
                    if($("#reason").val().trim()==""){
                        $.messager.alert("系统提示","申请理由不能为空");
                        return false;
                    }
                },
                success:function(result){
                    var result=eval('('+result+')');
                    if(result.success){
                        $.messager.alert("系统提示","登记成功");
                        closeDialog2();
                        $("#dg").datagrid("reload");
                    }else{
                        if (result.msg!=""){
                            $.messager.alert("系统提示",result.msg);
                        }else {

                            $.messager.alert("系统提示","登记失败");
                        }
                        return;
                    }
                }
            });

            /* var selectedRows=$("#dg").datagrid('getSelections');
             var row=selectedRows[0];*/

           /* $.ajax({
                //提交数据的类型 POST GET
                type:"POST",
                //提交的网址
                url:url,
                //提交的数据
                data:{siteId:row.siteId,"returnTime":$('#returnTime').datetimebox('getValue')},
                //返回数据的格式
                datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                //在请求之前调用的函数

                //成功返回之后调用的函数
                success:function(result){
                   // var result=eval('('+result+')');
                    if(result.success){
                        $.messager.alert("系统提示","登记成功");
                        closeDialog2();
                        $("#dg").datagrid("reload");
                    }else{
                        $.messager.alert("系统提示","登记失败");
                        return;
                    }

                },
                //调用出错执行的函数
                error: function(){
                    //请求出错处理
                }
            });*/
        };

        function openlookDialog(){
            var selectedRows=$("#dg").datagrid('getSelections');
            if(selectedRows.length!=1){
                $.messager.alert("系统提示","请选择一条要查看的数据！");
                return;
            }
            var row=selectedRows[0];
            $("#dlg").dialog("open").dialog("setTitle","查看场地信息明细");
            $('#fm').form('load',row);

        };



        function closeDialog(){
            $("#dlg").dialog("close");

            $("#fm").form("clear");


        };
        function closeDialog2() {
            $("#dlg2").dialog("close");
            $("#fm2").form("clear");
        };


        function getCurentDateStr()
        {
            var now = new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var clock = year + "-";
            if(month < 10) clock += "0";
            clock += month + "-";
            if(day < 10) clock += "0";
            clock += day;
            return clock;
        };

    </script>
</head>
<body style="margin:1px;">
<table id="dg" title="场地信息管理" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
       url="/siteInformation/findAllSiteInformation" fit="true" toolbar="#tb">
    <thead>
    <tr>
        <!--
                private Integer siteId;
                private String name;
                private String position;
                private String purpose;
                private String status;
                private Double price;
                private Date changeDate;
                private Integer adminId;
                private String detail;
        -->

        <th field="siteId" width="50" align="center">编号</th>
        <th field="name" width="60" align="center">场地名称</th>
        <th field="position" width="90" align="center">场地位置</th>
        <th field="purpose" width="85" align="center" >场地用途</th>
        <th field="detail" width="200" align="center" hidden="true">详细说明</th>
        <th field="status" width="80" align="center">使用情况</th>
        <th field="price" width="60" align="center">价格</th>
        <th field="adminName" width="60" align="center" hidden="true">修改人</th>
        <th field="changeDate" width="60" align="center" hidden="true">修改时间</th>

    </tr>
    </thead>
</table>
<div id="tb">
    <div>
        <a href="javascript:openAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">预约场地</a>
        <a href="javascript:openlookDialog()" class="easyui-linkbutton" iconCls="icon-tip" plain="true">查看详细</a>
    </div>
    <div>
        &nbsp;场地名称：&nbsp;<input class="easyui-combobox" name="name" id="name" style="width: 148px;"
                                data-options="
									url:'/siteInformation/findName',
									valueField:'id',
									textField:'text',
									panelHeight:'auto'">
        &nbsp;场地位置：&nbsp;<input class="easyui-combobox" name="position" id="position" style="width: 148px;"
                                data-options="
									url:'/siteInformation/findPosition',
									valueField:'id',
									textField:'text',
									panelHeight:'auto'">
        &nbsp;场地用途：&nbsp;<input class="easyui-combobox" name="purpose" id="purpose" style="width: 148px;"
                                data-options="
                                    url:'/siteInformation/findPurpose',
									valueField:'id',
									textField:'text',
									panelHeight:'auto'">
        &nbsp;使用情况：&nbsp;<input class="easyui-combobox" name="status" id="status" style="width: 135px;"
                                data-options="
                                    url:'/siteInformation/findStatus',
									valueField:'id',
									textField:'text',
									panelHeight:'auto',

                                    ">

        <a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>

<div id="dlg" class="easyui-dialog" style="width: 680px;height:350px;"
     closed="true"  closable="false" buttons="#dlg-buttons">
    <form id="fm"  enctype="multipart/form-data"  method="post">
        <table >
            <!--
               private Integer siteId;
               private String name;
               private String position;
               private String purpose;
               private String status;
               private Double price;
               private Date changeDate;
               private Integer adminId;
               private String detail;
       -->
            <tr><td><input name="siteId" id="siteId" type="hidden"></td></tr>
            <tr>
                <td>场地名称：</td>
                <td>
                    <input class="easyui-textbox" name="name" id="siteName"></input>
                </td>
            </tr>

            <tr>
                <td>位置：</td>
                <td>
                    <input class="easyui-textbox" name="position" id="sitePosition"></input></td>
                </td>
            </tr>
            <tr>
                <td>用途：</td>
                <td>
                    <input class="easyui-textbox" name="purpose" id="sitePurpose"></input></td>
                </td>
            </tr>
            <tr>
                <td>价格：</td>
                <td><input type="text" class="easyui-numberbox" name="price" id="sitePrice" value="100" data-options="min:0,precision:2"></input>
                </td>
            </tr>
            <tr>
                <td>场地状态：</td>
                <td>
                    <select id="siteStatus" class="easyui-combobox" name="status" style="width:147px;">
                        <option value="可租借" selected>可租借</option>
                        <option value="维修">维修</option>
                        <option value="已租借">已租借</option>
                        <option value="报废">报废</option>
                        <option value="特殊用途">特殊用途</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td valign="top">场地详细描述：</td>
                <td colspan="8">
                    <textarea rows="5" cols="60" id="SiteDetail" name="detail"></textarea>
                </td>
            </tr>

        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript: closeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<div id="dlg2" class="easyui-dialog" style="width: 680px;height:350px;"
     closed="true"  closable="false" buttons="#dlg-buttons2">
    <form id="fm2" method="post" >
        <table >
            <!--  private Integer siteYyId;
            private Integer userId;
            private Integer siteId;
            @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
            private Date applicationTime;
            @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
            private Date returnTime;
            private String status;
            private Integer amdinId;
            private String reason;-->
                <tr><td><input name="siteId" type="hidden"></td></tr>
            <tr>
                <td>预约日期：</td>
                <td>
                    <input class="easyui-datebox" name="applicationTime" id="applicationTime" style="width: 148px;"></input>
                </td>
                <td>时间段：</td>
                <td>
                   <input class="easyui-combobox" name="whenTime" id="whenTime" style="width: 135px;"
                                            data-options="
									valueField:'id',
									textField:'text',
									panelHeight:'auto',
                                    ">
                </td>
            </tr>
              <!--  <tr>
                    <td>归还时间：</td>
                    <td>
                        <input class="easyui-datebox" name="returnTime" id="returnTime" style="width: 148px;"></input>
                    </td>
                </tr>-->
            <tr>
                <td valign="top">填写预约申请理由：</td>
                <td colspan="8">
                    <textarea rows="5" cols="60" name="reason" id="reason"></textarea>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons2">
    <a href="javascript: saveSite()" id="btn2" class="easyui-linkbutton" iconCls="icon-ok">预约</a>
    <a href="javascript: closeDialog2()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>